#!/usr/bin/env python3
"""
这个脚本用于修复visualization.py中解码状态的日志问题，将日志记录修改为界面显示
"""

import re

def main():
    # 读取visualization.py文件内容
    with open('visualization.py', 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 修改解码状态日志记录，约在1345-1355行
    pattern = r'# 获取解码状态\s+decode_status_value = .*?else:\s+# 未知状态，记录具体状态值到日志\s+logger\.warning\(\s+f"发现未知解码状态.*?\)\s+decode_status = "未知解码状态"'
    replacement = '# 获取解码状态\n                decode_status_value = frame_decode_status & 0xFF\n                if decode_status_value == 0:\n                    decode_status = "解码完成"\n                elif decode_status_value == 1:\n                    decode_status = "解码错误"\n                elif decode_status_value == 2:\n                    decode_status = "未解码"\n                else:\n                    # 直接在状态文本中显示具体状态值，不写入日志\n                    decode_status = f"未知解码状态(0x{decode_status_value:02X})"'
    
    content = re.sub(pattern, replacement, content, flags=re.DOTALL)
    
    # 保存修改后的内容
    with open('visualization.py', 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("修复完成：解码状态日志记录已改为界面显示")

if __name__ == "__main__":
    main() 